#!/bin/bash

# 获取脚本所在目录的路径
script_dir=$(dirname "$0")

# 获取解压的文件夹（假设是以 .tar.gz 格式压缩的文件）
tar_file=$(ls -l "$script_dir" | grep '^d' | awk '{print $9}')

name=("flink" "spark" "hive" "jdk" "kafka" "hadoop" "zookeeper")
echo $tar_file

if [ -n $tar_file ]
then

    for file in $(ls "$script_dir/$tar_file")
    do
        #判断文件是否为压缩文件
        # 使用file命令获取文件类型
        file_type=$(file -b "$script_dir/$tar_file/${file}")
        # 判断文件类型
        if [[ $file_type == *"gzip compressed data"* || $file_type == *"bzip2 compressed data"* || $file_type == *"Zip archive data"* || $file_type == *"RAR archive data"* ]]; then
                tar -zxf "$script_dir/$tar_file/${file}" -C "$script_dir/$tar_file/"
                rm -rf "$script_dir/$tar_file/${file}"
        else
            echo "$file 不是可解压文件"
        fi

    done
    echo "解压完成！"
    
else
    echo "文件夹不存在"
fi
#移动文件
for file in $(ls "$script_dir/$tar_file")
do
    for i in ${name[@]}
    do
        if echo "$file" | grep -qi "$i"; then
            mkdir -p "$script_dir/$tar_file/$i"
            mv  $script_dir/${tar_file}/${file}/* "$script_dir/$tar_file/$i"
	        rm -rf  $script_dir/${tar_file}/${file}/
        fi  
    done
done


